* **************************************************************************** *
* Sierra Leone - Social Signaling and Childhood Immunization                   *
* Inferences about Types Conditional on Vaccination Decisions                  *
* **************************************************************************** *
/*
** Purpose:    Table:  Inferences about Types Conditional on Vaccination Decisions


*/
********************************************************************************
********************************************************************************

	* --------------------------------------------------------------------------
	** How would community members view you if you...
	**    took your child for all vaccinations? 

	use  "${Replicate_SocialSignals_dtaInter}/Endline_Survey_Data.dta", clear

	* Merge in the ANC treatment status:
	merge m:m clinic  using  "${Replicate_SocialSignals_dtaInter}/MasterData_PilotClinics.dta", gen(ANCtreat)


	* Label the treatment variable:
	lab var treat3   "Signal at 4"
	lab var treat4   "Signal at 5"
	lab var treat2   "Uninformative Bracelet"



	* --------------------------------------------------------------------------
	* Generate conditional outcomes:

	local   ViewMissed = " caring knowimportant nothingspecial "

	summ    concerned `ViewMissed'

	foreach  reason of local ViewMissed {
		replace `reason' = .                      if concerned == 0
	}


	* --------------------------------------------------------------------------
	* Demean control variables

	tab     arm_anc, gen(anc)

	foreach control in anc2 anc3 anc4  {
		sum  `control'                                    if concerned == 1  & intervention_arm==1, detail
		gen  `control'_dm     = `control' - `r(mean)'     if concerned == 1
	}

	tab     education_cat, gen(educ)

	local   ControlVars = " mother_age_w01 educ2 educ3 farm  birth2 birth3 birth4 birth5 "

	foreach control of local  ControlVars  {
		summ `control'                                    if concerned == 1  & intervention_arm==1, detail
		gen  `control'_dm     = `control' - `r(mean)'     if concerned == 1
	}

	local   ControlVars = " mother_age_w01_dm educ2_dm educ3_dm farm_dm birth2_dm birth3_dm birth4_dm birth5_dm "
	local   ANC_dm      = " anc2_dm anc3_dm anc4_dm "

	summ   `ControlVars' `ANC_dm'


	* --------------------------------------------------------------------------
	* Run Regression:

	local  ControlVars = " mother_age_w01_dm educ2_dm educ3_dm farm_dm birth2_dm birth3_dm birth4_dm birth5_dm "
	local  ANC_dm      = " anc2_dm anc3_dm anc4_dm "

	eststo clear
	
	foreach  outcome in caring knowimportant nothingspecial  {
		areg    `outcome'  treat3 treat4 treat2     `ControlVars'    `ANC_dm', absorb(strata) vce(bootstrap , reps(${RepsNum}) seed(${seed}) cluster(clinic))
		eststo
		test   treat3 = treat2
		estadd scalar treat2_treat3 = r(p)
		test   treat3 = treat4
		estadd scalar treat3_treat4 = r(p)
		test   treat2 = treat4
		estadd scalar treat2_treat4 = r(p)
		test   treat2 treat3 treat4
		estadd scalar bracelets     = r(p)
		estadd local Obs            = "`e(N)'"
		estadd scalar C_mean        = _b[_cons]
		eststo model_`outcome'
	}

	esttab  ///
	model_caring model_knowimportant model_nothingspecial               ///
	using "${Replicate_SocialSignals_ATables}/Table_ViewAllVaccines_raw.tex",              ///
	prehead("\begin{tabular}{l*{4}{c}} \toprule \\"                     ///
	"& \multicolumn{3}{c}{\textbf{How would community members view you if you...}} \\"   ///
	"& \multicolumn{3}{c}{\textbf{took your child for all vaccinations?}} \\ \\"  ///
	"\multicolumn{1}{l}{\textbf{\textbf{Dependent Variable:}}} & \multicolumn{1}{c}{\textbf{Caring/patient/serious}} & \multicolumn{1}{c}{\textbf{Know of importance}} & \multicolumn{1}{c}{\textbf{Think nothing special about me}}\\")  ///
	scalars("C_mean       Control Group mean"                             ///
	"Obs          Observations"                                   ///
	"treat2_treat3 \(S_{4}\) \(>\) 0: p(UI = S4)"                 ///
	"treat2_treat4 \(S_{5}\) \(>\) 0: p(UI = S5)"                 ///
	"treat3_treat4 p(S4 = S5)"                                    ///
	"bracelets Joint F-Test")                                     ///
	substitute(\(S\_{4}\) \(S_{4}\)  \(S\_{5}\) \(S_{5}\))                ///
	keep(_cons treat3 treat4 treat2)                                      ///
	varlabels(_cons "Control Group mean")                                 ///
	sfmt(3) ${StarsOpt}  nomtitles                                        ///
	addnotes("") label b(3) se(3)  nobaselevels noconstant noobs          ///
	nolines posthead("\midrule") postfoot("\bottomrule \end{tabular}") tex  ///
	replace

	filefilter "${Replicate_SocialSignals_ATables}/Table_ViewAllVaccines_raw.tex"      ///
	"${Replicate_SocialSignals_ATables}/Table_ViewAllVaccines_Controls_Cond.tex", from("[1em]") to(" ") replace
	erase	     "${Replicate_SocialSignals_ATables}/Table_ViewAllVaccines_raw.tex"



* **************************************************************************** *
* End of the Dofile !!!
* **************************************************************************** *
